home *** CD-ROM | disk | FTP | other *** search
/ EuroCD 3 / EuroCD 3.iso / Games / Doom / ADoom-0.8 / ADoom_src / amiga_music.s < prev    next >
Text File  |  1998-06-24  |  42KB  |  1,909 lines

  1.         mc68020
  2.         multipass
  3.     if (_eval(DEBUG)&$8000)
  4.         debug    on,lattice4
  5.     endc
  6.  
  7. ; 2 channel .MUS player
  8. ;
  9. ; Derived by Peter McGavin,
  10. ; mostly by cutting and pasting large chunks of code from Amiga .MUS player
  11. ; originally by Joseph Fenton, Microcode Solutions, jlfenton@ctaz.com
  12. ; and his brother Michael.
  13.  
  14. ; void I_InitMusic (void);
  15.  
  16. ; void I_ShutdownMusic (void);
  17.  
  18. ; void I_SetMusicVolume (int volume);    // Volume.
  19.  
  20. ; void I_PauseSong (int handle);    // PAUSE game handling.
  21.  
  22. ; void I_ResumeSong (int handle);
  23.  
  24. ; int I_RegisterSong (void *data);    // Registers a song handle to song data.
  25.  
  26. ;// Called by anything that wishes to start music.
  27. ;//  plays a song, and when the song is done,
  28. ;//  starts playing it again in an endless loop.
  29. ;// Horrible thing to do, considering.
  30. ; void I_PlaySong (int handle, int looping);
  31.  
  32. ; void I_StopSong (int handle);        // Stops a song over 3 seconds.
  33.  
  34. ; void I_UnRegisterSong (int handle);    // See above (register), then think backwards
  35.  
  36. ;------------------------------------------------------------------------
  37.         xdef    @I_InitMusic      ; Allocate audio channels and clear them.
  38.         xdef    @I_ShutdownMusic  ; Clear channels and free them.
  39.         xdef    @I_SetMusicVolume ; Do code equiv to J_VolBox.
  40.         xdef    @I_PauseSong      ; Do code equiv to DoPause.
  41.         xdef    @I_ResumeSong      ; Goes to J_PlayBox equiv code.
  42.         xdef    @I_RegisterSong      ; Do code equiv to LoadMUS; no need to actually load it
  43.                       ; as we are passed a pointer to it here.
  44.         xdef    @I_PlaySong      ; Do code equiv to J_PlayBox.
  45.         xdef    @I_StopSong      ; Do code equiv to J_StopBox.
  46.         xdef    @I_UnRegisterSong ; Do code equiv to FreeUpMUS.
  47.  
  48. ;------------------------------------------------------------------------
  49.         xref    _SysBase
  50.         xref    _DOSBase
  51.         xref    _GfxBase
  52.         xref    _custom
  53.         xref    _snd_MusicVolume
  54.         xref    _gametic
  55.         xref    _I_Error
  56.         xref    @M_CheckParm
  57.  
  58. ;------------------------------------------------------------------------
  59.  
  60. TICRATE        equ    35            ; see doomdef.h
  61.  
  62. CALLSYS        macro    ;FunctionName
  63.         jsr    _LVO\1(a6)
  64.         endm
  65.  
  66. CALLEXE        macro    ;FunctionName
  67.         movea.l    (_SysBase),a6
  68.         jsr    _LVO\1(a6)
  69.         endm
  70.  
  71. CALLDOS        macro    ;FunctionName
  72.         movea.l    (_DOSBase),a6
  73.         jsr    _LVO\1(a6)
  74.         endm
  75.  
  76. _LVOCreatePool    equ    -696            ; not in Macro68's autoincludes
  77. _LVODeletePool    equ    -702            ; not in Macro68's autoincludes
  78.  
  79. ;------------------------------------------------------------------------
  80. ; void I_InitMusic (void);
  81. ; Allocate audio channels and clear them.
  82.  
  83. @I_InitMusic    movem.l    d0-d7/a0-a6,-(sp)
  84.  
  85.         movea.l    #musicarg,a0
  86.         jsr    @M_CheckParm
  87.         tst.l    d0
  88.         beq    .exit
  89.  
  90.         suba.l    a1,a1            ; this task
  91.         CALLEXE FindTask
  92.         move.l    d0,AudioTask        ; set task to signal
  93.  
  94.         move.w    #162,(per)
  95.         move.w    #325,(per2)        ; 11025 Hz, NTSC
  96.         move.l    (_GfxBase),a6
  97.         move.w    (gb_DisplayFlags,a6),d0
  98.         btst    #PALn,d0
  99.         beq.b    2$
  100.         move.w    #161,(per)
  101.         move.w    #322,(per2)        ; 11025 Hz, PAL
  102. 2$
  103.         moveq    #0,d0
  104.         moveq    #0,d1
  105.         lea    AudioName,a0
  106.         lea    AudioIO,a1
  107.         clr.l    ioa_Length(a1)        ; don't allocate channels yet
  108.         CALLEXE OpenDevice
  109.         tst.l    d0
  110.         beq    1$
  111.  
  112.         move.l    #cantopenaud,-(sp)
  113.         jsr    _I_Error
  114.         bra    .exit
  115.  
  116. 1$        move.b    #-1,AudioOK
  117.         bsr    AllocChannels        ; allocate channels
  118. .exit
  119.         movem.l    (sp)+,d0-d7/a0-a6
  120.         rts
  121.  
  122. ;------------------------------------------------------------------------
  123. ; void I_ShutdownMusic (void);
  124. ; Clear channels and free them.
  125.  
  126. @I_ShutdownMusic
  127.         movem.l    d0-d7/a0-a6,-(sp)
  128.         tst.b    AudioOK
  129.         beq    .exit
  130.         bsr    @I_StopSong
  131.         bsr    @I_UnRegisterSong    ; kill old mus
  132.         bsr    FreeChannels
  133.         lea    AudioIO,a1
  134.         CALLEXE CloseDevice
  135.         clr.b    AudioCh
  136.         clr.b    AudioOK
  137. .exit        movem.l    (sp)+,d0-d7/a0-a6
  138.         rts
  139.  
  140. ;------------------------------------------------------------------------
  141. ; void I_SetMusicVolume (int volume);    // Volume.
  142. ; Do code equiv to J_VolBox.
  143.  
  144. @I_SetMusicVolume
  145.         movem.l    d0-d7/a0-a6,-(sp)
  146.         tst.b    AudioOK
  147.         beq    .exit
  148.  
  149.         move.l    d0,(_snd_MusicVolume)
  150.         lsl.w    #3,d0            ; * 8
  151.         move.w    d0,AudioCh2Vol
  152.         move.w    d0,AudioCh3Vol
  153. .exit        movem.l    (sp)+,d0-d7/a0-a6
  154.         rts
  155.  
  156. ;------------------------------------------------------------------------
  157. ; void I_PauseSong (int handle);    // PAUSE game handling.
  158. ; Do code equiv to DoPause.
  159.  
  160. @I_PauseSong    movem.l    d0-d7/a0-a6,-(sp)
  161.         tst.b    AudioOK
  162.         beq    .done
  163.  
  164.         btst    #1,Flags        ; file loaded?
  165.         beq.b    .done
  166.         bset    #0,MusFlag        ; stop
  167.         bclr    #2,Flags        ; playing?
  168.         beq.b    .done
  169. .stop        btst    #0,MusFlag        ; music stopped?
  170.         bne.b    .stop
  171.  
  172.         cmpi.b    #12,AudioCh        ; locked?
  173.         bne.b    .done
  174.         lea    _custom,a0        ; kill sound
  175.         moveq    #0,d0
  176.         move.w    d0,aud2+ac_vol(a0)
  177.         move.w    d0,aud3+ac_vol(a0)
  178.  
  179. .done        movem.l    (sp)+,d0-d7/a0-a6
  180.         rts
  181.  
  182. ;------------------------------------------------------------------------
  183. ; void I_ResumeSong (int handle);
  184. ; Goes to J_PlayBox equiv code.
  185.  
  186. @I_ResumeSong    movem.l    d0-d7/a0-a6,-(sp)
  187.         tst.b    AudioOK
  188.         beq    .exit
  189.  
  190.         btst    #1,Flags        ; file loaded?
  191.         beq.b    .nofile
  192.  
  193.         cmpi.b    #12,AudioCh        ; got all channels?
  194.         beq.b    .allch
  195.         bsr    AllocChannels        ; try to alloc, first
  196.         cmpi.b    #12,AudioCh        ; now?
  197.         beq.b    .allch
  198.  
  199.         move.l    #cantgetchan,-(sp)
  200.         jsr    _I_Error
  201.         bra    .exit
  202.  
  203. .allch        bset    #2,Flags        ; playing?
  204.         beq.b    .ok
  205. .nofile        rts
  206.  
  207. .ok        movea.l    MusPtr,a0
  208.         moveq    #0,d1
  209.         move.b    8(a0),d1        ; d1 = # of channels
  210.  
  211.         moveq    #0,d0
  212.         move.w    6(a0),d0        ; score start
  213.         ror.w    #8,d0
  214.         adda.l    d0,a0            ; a0 = start
  215.         bclr    #3,Flags        ; paused?
  216.         bne    .paused
  217.  
  218.         move.l    a0,MusIndex        ; MusIndex = start
  219.  
  220.         move.l    #QuietInst,Channel0
  221.         move.l    #QuietInst,Channel1
  222.         move.l    #QuietInst,Channel2
  223.         move.l    #QuietInst,Channel3
  224.         move.l    #QuietInst,Channel4
  225.         move.l    #QuietInst,Channel5
  226.         move.l    #QuietInst,Channel6
  227.         move.l    #QuietInst,Channel7
  228.         move.l    #QuietInst,Channel8
  229.         move.l    #QuietInst,Channel9
  230.         move.l    #QuietInst,Channel10
  231.         move.l    #QuietInst,Channel11
  232.         move.l    #QuietInst,Channel12
  233.         move.l    #QuietInst,Channel13
  234.         move.l    #QuietInst,Channel14
  235.         move.l    #QuietInst,Channel15
  236.  
  237.         clr.l    MusDelay        ; MusDelay = 0
  238.         clr.b    MusFlag            ; enable music
  239.         clr.l    VoiceAvail        ; all voices available
  240.  
  241.         clr.l    MyTicks            ; reset my timer
  242.  
  243. .paused        CALLEXE Disable
  244.         lea    _custom,a0
  245.         move.w    #$8200,intena(a0)    ; int enable
  246.         move.w    #$800c,dmacon(a0)    ; enable dma
  247.         bsr    AudioINT2        ; start audio
  248.         CALLSYS    Enable
  249.  
  250. .exit        movem.l    (sp)+,d0-d7/a0-a6
  251.         rts
  252.  
  253. ;------------------------------------------------------------------------
  254. ; int I_RegisterSong (void *data);    // Registers a song handle to song data.
  255. ; Do code equiv to LoadMUS; no need to actually load it
  256. ; as we are passed a pointer to it here.
  257.  
  258. @I_RegisterSong
  259.         movem.l    d0-d7/a0-a6,-(sp)
  260.         tst.b    AudioOK
  261.         beq    .done2
  262.  
  263.         move.l    a0,-(sp)        ; save data ptr
  264.  
  265.         bsr    @I_StopSong        ; stop current mus
  266.         bsr    @I_UnRegisterSong    ; kill old mus
  267.  
  268.         movea.l    (sp)+,a0
  269.         move.l    a0,MUSMemPtr
  270.  
  271.         cmpi.l    #$4D55531A,(a0)        ; "MUS",26
  272.         bne    .uerror            ; not a mus file
  273.  
  274.         move.l    MUSMemPtr(pc),MusPtr
  275.  
  276.         bsr    TestMUSFile
  277.         beq    .berror
  278.  
  279. ;--------
  280.  
  281.         move.l    InstrFile,d1
  282.         move.l    #MODE_OLDFILE,d2
  283.         CALLDOS    Open
  284.         move.l    d0,InstrHandle
  285.         beq    .midierror
  286.  
  287.         move.l    #MEMF_CLEAR,d0        ; any memory
  288.         move.l    #65536,d1        ; puddle size
  289.         move.l    #32768,d2        ; threshold size
  290.         bsr    CreatePool
  291.         move.l    a0,InstrPool        ; this was d0
  292.         beq    .merror
  293.  
  294.         movea.l    a0,a2            ; so was this
  295.         movea.l    MusPtr,a3
  296.  
  297.         move.w    #255,d0
  298.         lea    Instruments,a0
  299. .setinstr    move.l    #QuietInst,(a0)+
  300.         dbra    d0,.setinstr
  301.  
  302.         move.w    $C(a3),d4        ; instrCnt
  303.         ror.w    #8,d4
  304.         subq.w    #1,d4            ; for dbra
  305.  
  306.         lea    $10(a3),a3        ; instruments[]
  307.  
  308. .instrloop    moveq    #14,d0
  309.         movea.l    a2,a0
  310.         bsr    AllocPooled
  311.  
  312.         moveq    #0,d2
  313.         move.b    (a3)+,d2        ; instrument #
  314.         moveq    #0,d1
  315.         move.b    (a3)+,d1        ; offset to next instr. #
  316.         adda.l    d1,a3            ; skip it (whatever it is?)
  317.  
  318.         lea    Instruments,a0
  319.         move.l    d0,(a0,d2.w*4)
  320.         beq    .merror
  321.  
  322.         movea.l    d0,a4            ; instrument record
  323.  
  324.         bftst    (validInstr){d2:1}
  325.         beq    .next            ; no instrument
  326.  
  327.         move.l    InstrHandle,d1
  328.         lsl.l    #2,d2
  329.         moveq    #OFFSET_BEGINNING,d3
  330.         CALLDOS    Seek
  331.  
  332.         move.l    InstrHandle,d1
  333.         move.l    a4,d2
  334.         moveq    #4,d3
  335.         CALLSYS    Read            ; get instrument offset
  336.         addq.l    #1,d0
  337.         beq    .ferror            ; can't read file
  338.  
  339.         move.l    InstrHandle,d1
  340.         move.l    (a4),d2
  341.         moveq    #OFFSET_BEGINNING,d3
  342.         CALLSYS    Seek
  343.  
  344.         move.l    InstrHandle,d1
  345.         move.l    a4,d2
  346.         moveq    #14,d3
  347.         CALLSYS    Read            ; get instrument header
  348.         addq.l    #1,d0
  349.         beq    .ferror            ; can't read file
  350.  
  351.         move.l    in_Length(a4),d0
  352.         swap    d0
  353.         movea.l    a2,a0
  354.         bsr    AllocPooled
  355.         move.l    d0,in_Wave(a4)        ; wave data buffer
  356.         beq    .merror
  357.  
  358.         move.l    InstrHandle,d1
  359.         move.l    d0,d2
  360.         move.l    in_Length(a4),d3
  361.         swap    d3
  362.         CALLDOS    Read            ; get instrument samples
  363.         addq.l    #1,d0
  364.         beq    .ferror            ; can't read file
  365.  
  366.         move.b    #1,in_Flags(a4)
  367. .next        dbra    d4,.instrloop
  368.  
  369.         bset    #1,Flags        ; file loaded
  370.         bsr    FillEventBlocks
  371.  
  372. .done        btst    #1,Flags        ; success?
  373.         bne.b    .exit
  374.         bsr    @I_UnRegisterSong    ; kill MUS and instruments
  375.  
  376. .exit        move.l    InstrHandle,d1
  377.         beq.b    .done2
  378.         CALLDOS    Close
  379.         clr.l    InstrHandle
  380.  
  381. .done2        moveq    #1,d0            ; return handle=1
  382.         movem.l    (sp)+,d0-d7/a0-a6
  383.         rts
  384.  
  385. ;---------
  386.  
  387. .midierror    move.l    #midifileproblem,-(sp)
  388.         jsr    _I_Error
  389.         bra    .done
  390.  
  391. .ferror        move.l    #dosproblem,-(sp)
  392.         jsr    _I_Error
  393.         bra    .done
  394.  
  395. .merror        move.l    #memproblem,-(sp)
  396.         jsr    _I_Error
  397.         bra    .done
  398.  
  399. .uerror        move.l    #notmusfile,-(sp)
  400.         jsr    _I_Error
  401.         bra    .done
  402.  
  403. .berror        move.l    #damagedfile,-(sp)
  404.         jsr    _I_Error
  405.         bra    .done
  406.  
  407. ;------------------------------------------------------------------------
  408. ;// Called by anything that wishes to start music.
  409. ;//  plays a song, and when the song is done,
  410. ;//  starts playing it again in an endless loop.
  411. ;// Horrible thing to do, considering.
  412. ; void I_PlaySong (int handle, int looping);
  413. ; Do code equiv to J_PlayBox.
  414.  
  415. @I_PlaySong    movem.l    d0-d7/a0-a6,-(sp)
  416.         tst.b    AudioOK
  417.         beq    .exit
  418.  
  419.         move.l    #TICRATE*30,d0
  420.         add.l    (_gametic),d0
  421.         move.l    d0,(musicdies)
  422.  
  423.         bsr    @I_ResumeSong
  424.  
  425. .exit        movem.l    (sp)+,d0-d7/a0-a6
  426.         rts
  427.  
  428. ;------------------------------------------------------------------------
  429. ; void I_StopSong (int handle);        // Stops a song over 3 seconds.
  430. ; Do code equiv to J_StopBox.
  431.  
  432. @I_StopSong    movem.l    d0-d7/a0-a6,-(sp)
  433.  
  434.         move.l    #0,(looping)
  435.         move.l    #0,(musicdies)
  436.  
  437.         tst.b    AudioOK
  438.         beq    .exit
  439.  
  440.         bsr    @I_PauseSong
  441.         bsr    KillAllAud
  442.  
  443. .exit        movem.l    (sp)+,d0-d7/a0-a6
  444.         rts
  445.  
  446. ;------------------------------------------------------------------------
  447. ; void I_UnRegisterSong (int handle);    // See above (register), then think backwards
  448. ; Do code equiv to FreeUpMUS.
  449.  
  450. @I_UnRegisterSong
  451.         movem.l    d0-d7/a0-a6,-(sp)
  452.  
  453.         tst.b    AudioOK
  454.         beq    .free
  455.  
  456.         bclr    #1,Flags        ; still have anything?
  457.         beq.b    .free
  458.  
  459.         clr.l    MUSMemPtr
  460.         clr.l    MUSMemSize
  461.  
  462. .instr        tst.l    InstrPool
  463.         beq.b    .free
  464.  
  465.         movea.l    InstrPool,a0
  466.         bsr    DeletePool
  467.         clr.l    InstrPool
  468.  
  469. .free        movem.l    (sp)+,d0-d7/a0-a6
  470.         rts
  471.  
  472. ;------------------------------------------------------------------------
  473. ;------------------------------------------------------------------------
  474.  
  475. FillEventBlocks    lea    EventBlocks,a4
  476.         movea.l    MusPtr(pc),a0
  477.         move.w    6(a0),d0
  478.         ror.w    #8,d0
  479.         lea    (a0,d0.w),a2        ; a2 = start
  480.         movea.l    a2,a1            ; a1 = a2
  481. .loop        bsr    NextDelay
  482.         move.l    a1,d0
  483.         sub.l    a2,d0            ; d0 = ptr - start
  484.         move.w    d0,(a4)+        ; store
  485.         addq.l    #1,d1
  486.         bne.b    .loop
  487.         clr.w    (a4)            ; end of offsets
  488.         rts
  489.  
  490. NextDelay    bsr.b    MyNextEvent
  491.         cmpi.b    #6,d1            ; score end
  492.         beq.b    .dd
  493.         tst.b    d0
  494.         bpl.b    NextDelay
  495.  
  496.         moveq    #0,d1            ; time = 0
  497. .d1        move.b    (a1)+,d0        ; get byte
  498.         bpl.b    .d2
  499.         andi.w    #$7F,d0            ; kill sign bit
  500.         or.b    d0,d1            ; time = time + 7 bits
  501.         lsl.l    #7,d1            ; * 128
  502.         bra.b    .d1            ; get next 7 bits
  503. .d2        or.b    d0,d1            ; time = time + last 7 bits
  504.         rts
  505.  
  506. .dd        moveq    #-1,d1
  507.         rts
  508.  
  509. MyNextEvent    move.b    (a1)+,d0        ; d0 = event
  510.         moveq    #$70,d1
  511.         and.b    d0,d1            ; d1 = type<<4
  512.         bne.b    .e1
  513.  
  514. .e0        addq.l    #1,a1            ; + value
  515.         rts
  516.  
  517. .e1        lsr.b    #4,d1            ; d1 = type
  518.         cmpi.b    #6,d1            ; score end?
  519.         bne.b    .e2
  520.         subq.l    #1,a1
  521. .ed        rts
  522. .e2        cmpi.b    #5,d1            ; no event
  523.         beq.b    .ed
  524.         cmpi.b    #7,d1            ; no event
  525.         beq.b    .ed
  526.         cmpi.b    #1,d1            ; play
  527.         beq.b    .ep
  528.         cmpi.b    #4,d1            ; change?
  529.         bne.b    .e0
  530.         addq.l    #2,a1            ; + value1, value2
  531.         rts
  532. .ep        moveq    #0,d4
  533.         tst.b    (a1)+            ; + note
  534.         bmi.b    .e0            ; (+ volume, if b7 set)
  535.         rts
  536.  
  537.         moveq    #1,d0
  538.         rts
  539.  
  540. ;------------------------------------------------------------------------
  541.  
  542. TestMUSFile    movea.l    MusPtr(pc),a0
  543.         move.l    MUSMemSize(pc),d3    ; d3 = total file size
  544.         moveq    #0,d0
  545.         move.w    4(a0),d0
  546.         beq    .fail
  547.         ror.w    #8,d0            ; score length
  548.         moveq    #0,d1
  549.         move.w    6(a0),d1
  550.         ror.w    #8,d1            ; score start
  551.         cmpi.w    #18,d1            ; start < 18? (1 instr.)
  552.         blt    .fail
  553.         add.l    d1,d0            ; d0 = total size
  554.  
  555. ;        cmp.l    d0,d3            ; = file size?
  556. ;        bne    .fail
  557.  
  558.         move.l    d0,d3
  559.         move.l    d3,MUSMemSize
  560.  
  561.         move.w    12(a0),d2
  562.         beq.b    .fail
  563.         ror.w    #8,d2            ; d2 = instr. count
  564.         subq.w    #1,d2
  565.         lea    16(a0),a1        ; a1 = * instr. list
  566. .loop        addq.l    #1,a1            ; skip instr. value
  567.         moveq    #0,d0
  568.         move.b    (a1)+,d0        ; d0 = offset to next instr.
  569.         adda.l    d0,a1            ; skip info (?)
  570.         dbra    d2,.loop        ; next
  571.         move.l    a1,d0            ; d0 = * data following list
  572.         sub.l    a0,d0            ; - file start
  573.         cmp.l    d0,d1            ; = start?
  574.         bne.b    .fail
  575.         move.b    -1(a0,d3.l),d0        ; get last byte
  576.         lsr.b    #4,d0
  577.         cmpi.b    #6,d0            ; last byte = $6x? (end)
  578.         bne.b    .fail
  579.         moveq    #1,d0            ; file okay
  580.         rts
  581. .fail        moveq    #0,d0            ; yikes!
  582.         rts
  583.  
  584. ;------------------------------------------------------------------------
  585. ;------------------------------------------------------------------------
  586.  
  587. ; stop, clear, turn off
  588.  
  589. KillAllAud    cmpi.b    #12,AudioCh        ; locked?
  590.         bne.b    .vk
  591.  
  592.         lea    _custom,a0
  593.         move.l    #ClearBuf,aud2(a0)    ; re-init
  594.         move.w    #80,aud2+ac_len(a0)
  595.         move.w    (per,pc),aud2+ac_per(a0)
  596.         move.l    #ClearBuf,aud3(a0)
  597.         move.w    #80,aud3+ac_len(a0)
  598.         move.w    (per,pc),aud3+ac_per(a0)
  599.  
  600. .vk        clr.b    Voice0+vc_Flags        ; disable voices
  601.         clr.b    Voice1+vc_Flags
  602.         clr.b    Voice2+vc_Flags
  603.         clr.b    Voice3+vc_Flags
  604.         clr.b    Voice4+vc_Flags
  605.         clr.b    Voice5+vc_Flags
  606.         clr.b    Voice6+vc_Flags
  607.         clr.b    Voice7+vc_Flags
  608.         clr.b    Voice8+vc_Flags
  609.         clr.b    Voice9+vc_Flags
  610.         clr.b    Voice10+vc_Flags
  611.         clr.b    Voice11+vc_Flags
  612.         clr.b    Voice12+vc_Flags
  613.         clr.b    Voice13+vc_Flags
  614.         clr.b    Voice14+vc_Flags
  615.         clr.b    Voice15+vc_Flags
  616.  
  617.         rts
  618.  
  619. ;------------------------------------------------------------------------
  620. ;------------------------------------------------------------------------
  621.  
  622. AllocChannels    lea    AudioIO,a1
  623.         move.w    #ADCMD_ALLOCATE,IO_COMMAND(a1)
  624.         move.b    #ADIOF_NOWAIT+IOF_QUICK,IO_FLAGS(a1)
  625.         move.l    #AudioAlloc,ioa_Data(a1)
  626.         move.l    #1,ioa_Length(a1)
  627.         movea.l    IO_DEVICE(a1),a6
  628.         jsr    DEV_BEGINIO(a6)
  629.         tst.l    d0
  630.         beq    1$
  631.  
  632.         move.l    #cantgetchan,-(sp)
  633.         jsr    _I_Error
  634.         bra    .exit
  635.  
  636. 1$        lea    AudioIO,a1
  637.         move.w    #ADCMD_LOCK,IO_COMMAND(a1)
  638.         CALLEXE SendIO
  639.  
  640.         move.l    AudioIO+IO_UNIT,d0
  641.         move.b    d0,AudioCh
  642.         cmpi.b    #12,d0            ; all channels?
  643.         beq    2$
  644.  
  645.         move.l    #cantgetchan,-(sp)
  646.         jsr    _I_Error
  647.         bra    .exit
  648.  
  649. 2$        lea    _custom,a0
  650.         move.w    #$0600,intena(a0)    ; kill int enable
  651.         move.w    #$0600,intreq(a0)    ; kill request
  652.         move.w    #$00FF,adkcon(a0)    ; kill modulation
  653.         move.w    #$000C,dmacon(a0)    ; disable dma
  654.  
  655.         move.l    #ClearBuf,aud2(a0)
  656.         move.w    #80,aud2+ac_len(a0)
  657.         move.w    (per,pc),aud2+ac_per(a0)
  658.         move.w    #0,aud2+ac_vol(a0)
  659.  
  660.         move.l    #ClearBuf,aud3(a0)
  661.         move.w    #80,aud3+ac_len(a0)
  662.         move.w    (per,pc),aud3+ac_per(a0)
  663.         move.w    #0,aud3+ac_vol(a0)
  664.  
  665.         moveq    #INTB_AUD2,d0
  666.         lea    AInt2,a1
  667.         CALLEXE SetIntVector
  668.         move.l    d0,OldAInt2
  669.  
  670. .exit        rts
  671.  
  672. ;------------------------------------------------------------------------
  673.  
  674. FreeChannels    cmpi.b    #12,AudioCh
  675.         bne.b    .exit            ; no channels
  676.  
  677.         lea    _custom,a0
  678.         move.w    #$0600,intena(a0)    ; kill int enable
  679.         move.w    #$0600,intreq(a0)    ; kill request
  680.  
  681.         moveq    #INTB_AUD2,d0
  682.         movea.l    OldAInt2,a1
  683.         CALLEXE SetIntVector
  684.  
  685.         moveq    #$000c,d0
  686.         move.w    d0,_custom+dmacon    ; dma off
  687.         lea    AudioIO,a1
  688.         move.w    #ADCMD_FREE,IO_COMMAND(a1)
  689.         move.b    #IOF_QUICK,IO_FLAGS(a1)
  690.         movea.l    IO_DEVICE(a1),a6
  691.         jsr    DEV_BEGINIO(a6)
  692.         clr.l    AudioIO+IO_UNIT
  693.         clr.b    AudioCh
  694.  
  695. .exit        rts
  696.  
  697. ;--------------------------------------------------------------------
  698.  
  699.         cnop    0,16
  700.  
  701. AudioINT2    movem.l    d2-d6/a2-a4/a6,-(a7)
  702.  
  703.         btst    #0,MusFlag
  704.         beq.b    .cont
  705.  
  706.         lea    _custom,a0
  707.         move.w    #$0600,intena(a0)    ; kill int enable
  708.         move.w    #$0600,intreq(a0)    ; kill request
  709.  
  710.         clr.b    MusFlag
  711.         bra    .exit
  712.  
  713. .cont        subq.l    #1,MusDelay
  714.         bpl.b    .setaudio
  715.  
  716.         bsr    NextEvent
  717.  
  718. .setaudio    bchg    #1,MusFlag        ; switch buffers
  719.  
  720.         btst    #6,Flags        ; gadget down?
  721.         bne.b    .gad
  722.         addq.l    #1,MyTicks        ; increment my timer
  723.  
  724. .gad        lea    Voice0,a0        ; music voices
  725.         lea    AudioCh2Buf,a2
  726.         bsr    FillBuffer
  727.  
  728.         lea    _custom,a0
  729.         move.w    #INTF_AUD2,intreq(a0)
  730.  
  731.         move.l    AudioCh2Ptr,aud2(a0)
  732.         move.w    #40,aud2+ac_len(a0)        ; 80 samples
  733.         move.w    (per2,pc),aud2+ac_per(a0)    ; 11048Hz
  734.         move.w    AudioCh2Vol,aud2+ac_vol(a0)
  735.  
  736.         move.l    AudioCh2Ptr,aud3(a0)
  737.         move.w    #40,aud3+ac_len(a0)        ; 80 samples
  738.         move.w    (per2,pc),aud3+ac_per(a0)    ; 11048Hz
  739.         move.w    AudioCh2Vol,aud3+ac_vol(a0)
  740.  
  741. .exit        movem.l    (a7)+,d2-d6/a2-a4/a6
  742.         moveq    #0,d0
  743.         rts
  744.  
  745. ;------------------------------------------------------------------------
  746.  
  747.         CNOP    0,16
  748.  
  749. FillBuffer    moveq    #0,d0
  750.         btst    #1,MusFlag
  751.         beq.b    .swap
  752.         move.l    #80,d0
  753. .swap        movea.l    (a2),a4            ; chip buffer
  754.         adda.l    d0,a4
  755.         move.l    a4,4(a2)        ; AudioChxPtr
  756.  
  757.         lea    tempAudio,a1
  758.         moveq    #4,d0
  759. .cloop        clr.l    (a1)+
  760.         clr.l    (a1)+
  761.         clr.l    (a1)+
  762.         clr.l    (a1)+
  763.         dbra    d0,.cloop
  764.  
  765. .next        move.l    vc_Next(a0),d0        ; next voice
  766.         bne.b    .chkvoice
  767.  
  768.         lea    tempAudio,a1
  769.         moveq    #4,d0
  770. .mloop        move.l    (a1)+,(a4)+
  771.         move.l    (a1)+,(a4)+
  772.         move.l    (a1)+,(a4)+
  773.         move.l    (a1)+,(a4)+
  774.         dbra    d0,.mloop
  775.         rts
  776.  
  777. .chkvoice    movea.l    d0,a0
  778.         btst    #0,vc_Flags(a0)
  779.         beq.b    .next            ; not enabled
  780.  
  781.  
  782. ;------------------
  783. ; do voice
  784.  
  785.         lea    tempAudio,a1
  786.  
  787.         btst    #1,vc_Flags(a0)
  788.         beq.b    .1            ; not releasing
  789.  
  790.         subq.b    #1,vc_Vol(a0)
  791.         bpl.b    .1
  792.         clr.b    vc_Vol(a0)
  793.         clr.b    vc_Flags(a0)        ; voice off
  794.         bra.b    .next
  795.  
  796. .1        move.b    vc_Vol(a0),d5
  797.         bfffo    d5{24:8},d5        ; 0-127 -> 32-24
  798.         subi.b    #24,d5            ;          8-0
  799.         addq.b    #2,d5            ; /4
  800.  
  801.         movem.l    vc_Index(a0),d1-d4    ; index,step,loop,length
  802.  
  803.         movea.l    vc_Channel(a0),a3
  804.         move.l    ch_Pitch(a3),d0
  805.         muls.l    d0,d6:d2
  806.         move.w    d6,d2
  807.         swap    d2
  808.         add.l    vc_Step(a0),d2        ; final sample rate
  809.  
  810.         movea.l    vc_Wave(a0),a3        ; sample data
  811.  
  812.         moveq    #79,d6            ; 80 samples
  813.  
  814. .floop        moveq    #0,d0
  815.         swap    d1
  816.         move.b    (a3,d1.w),d0        ; sample
  817.         swap    d1
  818.         asr.b    d5,d0
  819.         add.b    d0,(a1)+
  820.  
  821.         add.l    d2,d1
  822.         cmp.l    d4,d1
  823.         blo.b    .2
  824.         sub.l    d4,d1
  825.         add.l    d3,d1
  826.         tst.l    d3
  827.         beq.b    .3            ; no looping
  828. .2        dbra    d6,.floop
  829.         bra.b    .done            ; done with voice 1
  830.  
  831. ; ran out of data
  832. .3        clr.b    vc_Flags(a0)        ; voice off
  833.  
  834. .done        move.l    d1,vc_Index(a0)
  835.         bra    .next
  836.  
  837. ;------------------------------------------------------------------------
  838.  
  839.         CNOP    0,16
  840.  
  841. NextEvent    movea.l    MusIndex,a1
  842.  
  843. .0        move.b    (a1)+,d0        ; get next event
  844.         move.b    d0,d1
  845.         lsr.b    #3,d1
  846.         andi.w    #$E,d1            ; d1 = event type * 2
  847.         lea    EventTable,a0
  848.         move.w    (a0,d1.w),d1
  849.         jsr    (a0,d1.w)        ; do event
  850.         tst.b    d0
  851.         bpl.b    .0            ; more events
  852.  
  853.         moveq    #0,d1            ; time = 0
  854. .1        move.b    (a1)+,d0        ; get byte
  855.         bpl.b    .2
  856.  
  857.         andi.w    #$7F,d0            ; kill sign bit
  858.         or.b    d0,d1            ; time = time + 7 bits
  859.         lsl.l    #7,d1            ; * 128
  860.         bra.b    .1            ; get next 7 bits
  861.  
  862. .2        or.b    d0,d1            ; time = time + last 7 bits
  863.         subq.l    #1,d1            ; delay = time - 1
  864.         bmi.b    .0            ; (no delay)
  865.  
  866.         btst    #6,Flags        ; gadget down?
  867.         beq.b    .nogad
  868.         btst    #7,Flags
  869.         beq.b    .rev
  870.         add.l    d1,MyTicks        ; add to my timer
  871.         addq.l    #1,MyTicks        ; + 1
  872.         lsr.l    #3,d1            ; delay = delay / 8
  873.         bra.b    .nogad
  874. .rev        bsr.b    PrevBlock
  875.  
  876. .nogad        move.l    d1,MusDelay        ; store delay
  877.         move.l    a1,MusIndex        ; store index
  878.         rts
  879.  
  880. PrevBlock    move.l    PrevDelay,d0
  881.         sub.l    d0,MyTicks        ; sub previous value
  882.         addq.l    #1,d1
  883.         move.l    d1,PrevDelay
  884.         move.l    a1,d1            ; d1 = current ptr
  885.         movea.l    MusPtr(pc),a0
  886.         move.w    6(a0),d0
  887.         ror.w    #8,d0
  888.         lea    (a0,d0.w),a0        ; a0 = start
  889.         cmp.l    a0,d1            ; at start?
  890.         beq.b    .done
  891.         lea    EventBlocks,a1
  892. .loop        moveq    #0,d0
  893.         move.w    (a1)+,d0        ; offset
  894.         beq.b    .done            ; (not found)
  895.         add.l    a0,d0            ; ptr
  896.         cmp.l    d1,d0            ; = current?
  897.         bne.b    .loop
  898.         subq.l    #4,a1
  899.         cmpa.l    #EventBlocks,a1        ; 2nd block?
  900.         bls.b    .done
  901.         moveq    #0,d0
  902.         move.w    -(a1),d0        ; offset prev block
  903.         add.l    a0,d0
  904.         movea.l    d0,a1            ; ptr = prev block
  905.         moveq    #0,d1            ; delay = 0
  906.         rts
  907. .done        movea.l    a0,a1            ; ptr = start
  908.         moveq    #0,d1            ; delay = 0
  909.         clr.l    MyTicks            ; reset timer
  910.         rts
  911.  
  912. ;------------------------------------------------------------------------
  913.  
  914. Release        moveq    #15,d1
  915.         and.b    d0,d1            ; d1 = channel
  916.  
  917.         lea    Channels,a0
  918.         movea.l    (a0,d1.w*4),a0        ; channel record
  919.         movea.l    ch_Map(a0),a0        ; channel map
  920.  
  921.         move.b    (a1)+,d1        ; note #
  922.         moveq    #0,d2
  923.         move.b    (a0,d1.w),d2        ; voice #
  924.         beq.b    .exit            ; no mapping
  925.  
  926.         clr.b    (a0,d1.w)        ; clear mapping
  927.         move.l    VoiceAvail,d3
  928.         bclr    d2,d3            ; voice free for use
  929.         move.l    d3,VoiceAvail
  930.  
  931.         lea    Voices,a0
  932.         movea.l    (a0,d2.w*4),a0        ; voice
  933.         bset    #1,vc_Flags(a0)        ; do release
  934.  
  935. .exit        rts
  936.  
  937. ;------------------------------------------------------------------------
  938.  
  939. PlayNote    moveq    #15,d1
  940.         and.b    d0,d1            ; d1 = channel
  941.  
  942.         lea    Channels,a0
  943.         movea.l    (a0,d1.w*4),a2        ; channel record
  944.         movea.l    ch_Map(a2),a0        ; channel map
  945.  
  946.         moveq    #-1,d2            ; no volume change
  947.         move.b    (a1)+,d1        ; note #
  948.         bclr    #7,d1
  949.         beq.b    .getvc            ; no volume
  950.  
  951.         moveq    #0,d2
  952.         move.b    (a1)+,d2        ; volume
  953.  
  954. .getvc        moveq    #0,d3
  955.         move.l    VoiceAvail,d4
  956. .vloop        bset    d3,d4
  957.         beq.b    .foundfree
  958.         addq.b    #1,d3
  959.         cmpi.b    #16,d3
  960.         bne.b    .vloop
  961. ; no free voices
  962.         rts
  963.  
  964.  
  965. .foundfree    move.b    d3,(a0,d1.w)        ; voice mapping
  966.         move.l    d4,VoiceAvail
  967.  
  968.         lea    Voices,a0
  969.         movea.l    (a0,d3.w*4),a3        ; voice
  970.         btst    #7,vc_Flags(a3)
  971.         bne.b    .exit            ; sfx using channel
  972.  
  973.         tst.b    d2
  974.         bmi.b    .skip
  975.         move.b    d2,ch_Vol(a2)        ; new channel volume
  976. .skip        move.b    ch_Vol(a2),vc_Vol(a3)
  977.  
  978.         moveq    #15,d2
  979.         and.b    d0,d2
  980.         cmpi.b    #15,d2
  981.         beq.b    .percussion
  982.  
  983.         move.l    ch_Instr(a2),a4        ; instrument record
  984.  
  985.         lea    NoteTable,a0
  986.         moveq    #72,d2            ; middle c
  987.         sub.b    in_Base(a4),d2
  988.         add.b    d1,d2
  989.         move.l    (a0,d2.w*4),vc_Step(a3)    ; step value for note
  990.  
  991.         clr.l    vc_Index(a3)
  992.  
  993.         move.l    a2,vc_Channel(a3)    ; back link (for pitch wheel)
  994.  
  995.         move.l    in_Wave(a4),vc_Wave(a3)
  996.         move.l    in_Loop(a4),vc_Loop(a3)
  997.         move.l    in_Length(a4),vc_Length(a3)
  998.         move.b    in_Flags(a4),vc_Flags(a3)
  999. .exit        rts
  1000.  
  1001. ; for the percussion channel, the note played sets the percussion instrument
  1002.  
  1003. .percussion    move.l    #65536,vc_Step(a3)    ; sample rate always 1.0
  1004.  
  1005.         clr.l    vc_Index(a3)
  1006.  
  1007.         move.l    a2,vc_Channel(a3)    ; back link
  1008.  
  1009.         addi.b    #100,d1            ; percussion instruments
  1010.  
  1011.         lea    Instruments,a0
  1012.         move.l    (a0,d1.w*4),a0        ; instrument record
  1013.         move.l    in_Wave(a0),vc_Wave(a3)
  1014.         move.l    in_Loop(a0),vc_Loop(a3)
  1015.         move.l    in_Length(a0),vc_Length(a3)
  1016.         move.b    in_Flags(a0),vc_Flags(a3)
  1017.         rts
  1018.  
  1019. ;------------------------------------------------------------------------
  1020.  
  1021. Pitch        moveq    #15,d1
  1022.         and.b    d0,d1            ; d1 = channel
  1023.  
  1024.         lea    Channels,a0
  1025.         movea.l    (a0,d1.w*4),a2        ; channel record
  1026.  
  1027.         moveq    #0,d1
  1028.         move.b    (a1)+,d1        ; pitch wheel setting
  1029.         lea    PitchTable,a0
  1030.         move.l    (a0,d1.w*4),ch_Pitch(a2)
  1031.         rts
  1032.  
  1033. ;------------------------------------------------------------------------
  1034.  
  1035. Tempo        addq.l    #1,a1            ; skip value
  1036.         rts
  1037.  
  1038. ;------------------------------------------------------------------------
  1039.  
  1040. ChangeCtrl    moveq    #15,d1
  1041.         and.b    d0,d1            ; d1 = channel
  1042.  
  1043.         lea    Channels,a0
  1044.         movea.l    (a0,d1.w*4),a2        ; channel
  1045.  
  1046.         move.b    (a1)+,d1        ; get controller
  1047.  
  1048.         moveq    #0,d2
  1049.         move.b    (a1)+,d2        ; value
  1050.  
  1051.         tst.b    d1
  1052.         bne.b    .1
  1053.  
  1054. ; set channel instrument
  1055.  
  1056.         lea    Instruments,a0
  1057.         move.l    (a0,d2.w*4),ch_Instr(a2)
  1058.         bne.b    .0
  1059.         move.l    #QuietInst,ch_Instr(a2)
  1060. .0        rts
  1061.  
  1062. .1        cmpi.b    #3,d1            ; volume?
  1063.         bne.b    .2
  1064.  
  1065. ; set channel volume
  1066.  
  1067.         move.b    d2,ch_Vol(a2)
  1068.         rts
  1069.  
  1070. .2        cmpi.b    #4,d1            ; pan?
  1071.         bne.b    .exit
  1072.  
  1073. ; set channel pan
  1074.  
  1075.         move.b    d2,ch_Pan(a2)
  1076. .exit        rts
  1077.  
  1078. ;------------------------------------------------------------------------
  1079.  
  1080. NoEvent        rts
  1081.  
  1082. ;------------------------------------------------------------------------
  1083.  
  1084. EndScore    btst    #4,Flags        ; loop?
  1085.         beq.b    .loop
  1086.  
  1087.         lea    _custom,a0
  1088.         move.w    #$0600,intena(a0)    ; kill int enable
  1089.         move.w    #$0600,intreq(a0)    ; kill request
  1090.         clr.b    MusFlag            ; clear mus flag
  1091.         bclr    #2,Flags        ; kill playing flag
  1092.         moveq    #0,d0
  1093.         move.w    d0,aud2+ac_vol(a0)    ; kill old audio
  1094.         move.w    d0,aud3+ac_vol(a0)
  1095.         bsr    KillAllAud
  1096.         addq.l    #8,a7            ; pop NextEvent, AudioInt
  1097.         movem.l    (a7)+,d2-d6/a2-a4/a6    ; return from interrupt
  1098.         moveq    #0,d0
  1099.         rts
  1100.  
  1101. .loop        movea.l    MusPtr,a1
  1102.         moveq    #0,d1
  1103.         move.w    6(a1),d1        ; score start
  1104.         ror.w    #8,d1
  1105.         adda.l    d1,a1            ; a1 = start
  1106.  
  1107.         clr.l    MyTicks            ; reset my timer
  1108.         rts
  1109.  
  1110. ;------------------------------------------------------------------------
  1111. ;--------------------------------------------------------------------
  1112.  
  1113.         cnop    0,4
  1114.  
  1115. CreatePool    movea.l    _SysBase,a1
  1116.         cmpi.w    #39,LIB_VERSION(a1)
  1117.         blt.b    .nopools        ; change to bra for debugging
  1118.  
  1119.         move.l    a6,-(sp)
  1120.         movea.l    a1,a6
  1121.         CALLSYS    CreatePool
  1122.         movea.l    (sp)+,a6
  1123.         rts
  1124.  
  1125. .nopools    movem.l    d2-d7/a2-a6,-(sp)
  1126.         move.l    d0,d4            ; memory attributes
  1127.         move.l    d1,d3            ; amount to allocate when low
  1128.         move.l    d2,d5            ; size of when not to use pool
  1129.  
  1130.         exg.l    d0,d1            ; swap flags and size
  1131.         movea.l    a1,a6
  1132.         CALLSYS    AllocMem        ; get first block
  1133.         movea.l    d0,a0
  1134.         tst.l    d0
  1135.         beq.b    .exit            ; no memory!
  1136.  
  1137.         movem.l    d3-d5,(a0)        ; puddleSize, Flags,Threshold
  1138.         clr.l    12(a0)            ; no next block
  1139.         lea    24(a0),a1        ; first free location here
  1140.         move.l    a1,16(a0)
  1141.         subi.l    #24,d3            ; for header info
  1142.         move.l    d3,20(a0)        ; amount free in this block
  1143.  
  1144. .exit        movem.l    (sp)+,d2-d7/a2-a6
  1145.         rts
  1146.  
  1147.         cnop    0,4
  1148.  
  1149. DeletePool    movea.l    _SysBase,a1
  1150.         cmpi.w    #39,LIB_VERSION(a1)
  1151.         blt.b    .nopools        ; change to bra for debugging
  1152.  
  1153.         move.l    a6,-(sp)
  1154.         movea.l    a1,a6
  1155.         CALLSYS    DeletePool
  1156.         movea.l    (sp)+,a6
  1157.         rts
  1158.  
  1159. .nopools    movem.l    d2-d7/a2-a6,-(sp)
  1160.         move.l    a0,d2            ; first block
  1161.         beq.b    .exit            ; safety check
  1162.  
  1163.         movea.l    a1,a6
  1164.  
  1165. .loop        movea.l    d2,a1            ; pointer to block
  1166.         move.l    (a1),d0            ; size of block
  1167.         move.l    12(a1),d2        ; next block
  1168.         CALLSYS    FreeMem
  1169.         tst.l    d2
  1170.         bne.b    .loop
  1171.  
  1172. .exit        movem.l    (sp)+,d2-d7/a2-a6
  1173.         rts
  1174.  
  1175.         cnop    0,4
  1176.  
  1177. AllocPooled    movea.l    _SysBase,a1
  1178.         cmpi.w    #39,LIB_VERSION(a1)
  1179.         blt.b    .nopools        ; change to bra for debugging
  1180.  
  1181.         move.l    a6,-(sp)
  1182.         movea.l    a1,a6
  1183.         CALLSYS    AllocPooled
  1184.         movea.l    (sp)+,a6
  1185.         rts
  1186.  
  1187. .nopools    movem.l    d2-d7/a2-a6,-(sp)
  1188.         move.l    a0,d2
  1189.         beq.b    .exit            ; safety check
  1190.  
  1191.         addq.l    #3,d0
  1192.         andi.b    #$FC,d0            ; long align size
  1193.  
  1194.         movea.l    a1,a6
  1195.  
  1196.         cmp.l    8(a0),d0        ; check threshold
  1197.         blt.b    .chkpuddles        ; allocate from puddles
  1198.  
  1199.         addi.l    #24,d0            ; for header
  1200.         move.l    d0,d3            ; save size
  1201.         move.l    4(a0),d1        ; mem attrs
  1202.         CALLSYS    AllocMem
  1203.         movea.l    d0,a0
  1204.         tst.l    d0
  1205.         beq.b    .exit            ; no memory
  1206.  
  1207.         move.l    d3,(a0)            ; size of block
  1208.         clr.l    20(a0)            ; no free space in here
  1209.  
  1210.         movea.l    d2,a1            ; pool header
  1211.         move.l    12(a1),d1
  1212.         move.l    a0,12(a1)        ; splice in block
  1213.         move.l    d1,12(a0)        ; relink next block
  1214.         lea    24(a0),a0        ; skip over header
  1215.  
  1216. .exit        move.l    a0,d0
  1217.         movem.l    (sp)+,d2-d7/a2-a6
  1218.         rts
  1219.  
  1220.         cnop    0,4
  1221.  
  1222. .chkpuddles    cmp.l    20(a0),d0        ; check free space
  1223.         blt.b    .gotspace
  1224.  
  1225.         movea.l    12(a0),a0        ; next block
  1226.         move.l    a0,d1
  1227.         bne.b    .chkpuddles
  1228.  
  1229. ; not enough free space in existing puddles, create another
  1230.  
  1231.         move.l    d0,d6            ; save size
  1232.  
  1233.         movea.l    d2,a0            ; pool header
  1234.         movem.l    (a0),d3-d5
  1235.         movem.l    (a0),d0-d1
  1236.         CALLSYS    AllocMem        ; get block
  1237.         movea.l    d0,a0
  1238.         tst.l    d0
  1239.         beq.b    .out            ; no memory!
  1240.  
  1241.         movea.l    d2,a1            ; pool header
  1242.         movem.l    d3-d5,(a0)        ; puddleSize, Flags,Threshold
  1243.         move.l    12(a1),12(a0)        ; next block
  1244.         move.l    a0,12(a1)        ; splice in block
  1245.         lea    24(a0),a1        ; first free location here
  1246.         move.l    a1,16(a0)
  1247.         subi.l    #24,d3            ; for header info
  1248.         move.l    d3,20(a0)        ; amount free in this block
  1249.  
  1250.         move.l    d6,d0            ; restore size
  1251.  
  1252. .gotspace    sub.l    d0,20(a0)        ; sub from amount free
  1253.         bmi.b    .err            ; threshold >= puddlesize!
  1254.  
  1255.         move.l    16(a0),a1        ; free space
  1256.         add.l    d0,16(a0)        ; next free space
  1257.  
  1258.         movea.l    a1,a0
  1259.         bra.b    .out
  1260.  
  1261. .err        add.l    d0,20(a0)        ; restore free space
  1262.         moveq    #0,d0
  1263.         suba.l    a0,a0            ; no memory
  1264.  
  1265. .out        move.l    a0,d0
  1266.         movem.l    (sp)+,d2-d7/a2-a6
  1267.         rts
  1268.  
  1269. ;------------------------------------------------------------------------
  1270. ;------------------------------------------------------------------------
  1271. ;------------------------------------------------------------------------
  1272. ;------------------------------------------------------------------------
  1273.  
  1274. MUSMemPtr    dc.l    0
  1275. MUSMemSize    dc.l    0
  1276.  
  1277. ;------------------------------------------------------------------------
  1278.  
  1279. midifileproblem    dc.b    "Error opening MIDI_Instruments file!",0
  1280.  
  1281. dosproblem    dc.b    "Error reading MIDI_Instruments file!",0
  1282.  
  1283. memproblem    dc.b    "Not enough memory for music!",0
  1284.  
  1285. notmusfile    dc.b    "Music lump in WAD file is not .MUS format!",0
  1286.  
  1287. damagedfile    dc.b    "Damaged MIDI_Instruments or WAD file!",0
  1288.  
  1289. cantopenaud    dc.b    "Can't open audio.device for music!",0
  1290.  
  1291. cantgetchan    dc.b    "Can't allocate channels for music!",0
  1292.  
  1293.         cnop    0,4
  1294.  
  1295. ;------------------------------------------------------------------------
  1296. ; bit 0 = close, bit 1 = file loaded, bit 2 = playing, bit 3 = paused
  1297. ; bit 4 = loop, bit 5 = attention, bit 6 = gadget down, bit 7 = rev/FF
  1298. Flags        dc.b    0
  1299. Flags2        dc.b    0            ; backup of Flags
  1300.  
  1301. ; bit 0,1 = dotick
  1302. Flags3        dc.b    0
  1303.  
  1304.         cnop    0,4
  1305. per        dc.w    0
  1306. per2        dc.w    0    ; period for 11048 Hz
  1307.  
  1308. ;------------------------------------------------------------------------
  1309.         cnop    0,4
  1310.  
  1311. EventTable    dc.w    Release-EventTable
  1312.         dc.w    PlayNote-EventTable
  1313.         dc.w    Pitch-EventTable
  1314.         dc.w    Tempo-EventTable
  1315.         dc.w    ChangeCtrl-EventTable
  1316.         dc.w    NoEvent-EventTable
  1317.         dc.w    EndScore-EventTable
  1318.         dc.w    NoEvent-EventTable
  1319.  
  1320. ;------------------------------------------------------------------------
  1321.  
  1322.         cnop    0,4
  1323.  
  1324. looping        dc.l    0
  1325. musicdies    dc.l    -1
  1326.  
  1327. MyTicks        dc.l    0
  1328.  
  1329. PrevDelay    dc.l    0
  1330.  
  1331. AudioPort    dc.l    0,0
  1332.         dc.b    NT_MSGPORT,0        ; LN_TYPE, LN_PRI
  1333.         dc.l    0            ; LN_NAME
  1334.         dc.b    PA_SIGNAL        ; mp_Flags
  1335.         dc.b    0            ; mp_SigBit
  1336. AudioTask    dc.l    0            ; mp_SigTask
  1337. .1        dc.l    .2
  1338. .2        dc.l    0
  1339.         dc.l    .1
  1340.  
  1341.         cnop    0,4
  1342.  
  1343. AudioIO        dc.l    0,0
  1344.         dc.b    NT_REPLYMSG,0        ; LN_TYPE, LN_PRI
  1345.         dc.l    0            ; LN_NAME
  1346.         dc.l    AudioPort        ; mn_ReplyPort
  1347.         dc.w    68            ; mn_Length
  1348.         dc.l    0            ; IO_DEVICE
  1349.         dc.l    0            ; IO_UNIT
  1350.         dc.w    0            ; IO_COMMAND
  1351.         dc.b    0            ; IO_FLAGS
  1352.         dc.b    0            ; IO_ERROR
  1353.         dc.w    0            ; ioa_AllocKey
  1354.         dc.l    0            ; ioa_Data
  1355.         dc.l    0            ; ioa_Length
  1356.         dc.w    0            ; ioa_Period
  1357.         dc.w    0            ; ioa_Volume
  1358.         dc.w    0            ; ioa_Cycles
  1359.         dc.l    0,0            ; ioa_WriteMsg
  1360.         dc.b    0,0
  1361.         dc.l    0
  1362.         dc.l    0
  1363.         dc.w    0
  1364.  
  1365.         cnop    0,4
  1366.  
  1367. AInt2        dc.l    0,0
  1368.         dc.b    NT_INTERRUPT,0        ; LN_TYPE, LN_PRI
  1369.         dc.l    TPortName        ; LN_NAME
  1370.         dc.l    0            ; IS_DATA
  1371.         dc.l    AudioINT2        ; IS_CODE
  1372.  
  1373. MusPtr        dc.l    0
  1374. MusIndex    dc.l    0
  1375. MusDelay    dc.l    0
  1376. OldAInt2    dc.l    0
  1377.  
  1378. AudioAlloc    dc.b    $0c            ; Amiga channels to allocate
  1379.  
  1380. AudioName    dc.b    'audio.device',0
  1381. TPortName    dc.b    'ADoom-MUS',0
  1382. AudioOK        dc.b    0
  1383. AudioCh        dc.b    0
  1384. musicarg    dc.b    "-music",0
  1385.  
  1386. ;--------------------------------------
  1387.  
  1388.         CNOP    0,4
  1389.  
  1390. ; bit set if voice is in use (0-15=music voices,16-31=sfx voices)
  1391.  
  1392. VoiceAvail    dc.l    0
  1393.  
  1394.  
  1395. ; bit 0 = stop processing, bit 1 = buffer indicator
  1396.  
  1397. MusFlag        dc.b    0
  1398.  
  1399. ;--------------------------------------------------------------------
  1400.  
  1401.         CNOP    0,4
  1402.  
  1403. NoteTable    dc.l    65536/64,69433/64,73562/64,77936/64,82570/64,87480/64,92682/64,98193/64,104032/64,110218/64,116772/64,123715/64
  1404.         dc.l    65536/32,69433/32,73562/32,77936/32,82570/32,87480/32,92682/32,98193/32,104032/32,110218/32,116772/32,123715/32
  1405.         dc.l    65536/16,69433/16,73562/16,77936/16,82570/16,87480/16,92682/16,98193/16,104032/16,110218/16,116772/16,123715/16
  1406.         dc.l    65536/8,69433/8,73562/8,77936/8,82570/8,87480/8,92682/8,98193/8,104032/8,110218/8,116772/8,123715/8
  1407.         dc.l    65536/4,69433/4,73562/4,77936/4,82570/4,87480/4,92682/4,98193/4,104032/4,110218/4,116772/4,123715/4
  1408.         dc.l    65536/2,69433/2,73562/2,77936/2,82570/2,87480/2,92682/2,98193/2,104032/2,110218/2,116772/2,123715/2
  1409.         dc.l    65536,69433,73562,77936,82570,87480,92682,98193,104032,110218,116772,123715
  1410.         dc.l    65536*2,69433*2,73562*2,77936*2,82570*2,87480*2,92682*2,98193*2,104032*2,110218*2,116772*2,123715*2
  1411.         dc.l    65536*4,69433*4,73562*4,77936*4,82570*4,87480*4,92682*4,98193*4,104032*4,110218*4,116772*4,123715*4
  1412.         dc.l    65536*8,69433*8,73562*8,77936*8,82570*8,87480*8,92682*8,98193*8,104032*8,110218*8,116772*8,123715*8
  1413.         dc.l    65536*16,69433*16,73562*16,77936*16,82570*16,87480*16,92682*16,98193*16
  1414.  
  1415. ;------------------------------------------------------------------------
  1416.  
  1417. PitchTable:
  1418.  
  1419. pitch_ix    SET    128
  1420.  
  1421.         REPT    128
  1422.         dc.l    -3678*pitch_ix/64
  1423. pitch_ix    SET    pitch_ix-1
  1424.         ENDR
  1425.  
  1426.         REPT    128
  1427.         dc.l    3897*pitch_ix/64
  1428. pitch_ix    SET    pitch_ix+1
  1429.         ENDR
  1430.  
  1431. ;------------------------------------------------------------------------
  1432.  
  1433.         CNOP    0,4
  1434.  
  1435. AudioCh2Buf    dc.l    chipbuffer2
  1436. AudioCh2Ptr    dc.l    chipbuffer2
  1437. AudioCh2Vol    dc.w    64
  1438.  
  1439.         CNOP    0,4
  1440.  
  1441. AudioCh3Buf    dc.l    chipbuffer3
  1442. AudioCh3Ptr    dc.l    chipbuffer3
  1443. AudioCh3Vol    dc.w    64
  1444.  
  1445. ;------------------------------------------------------------------------
  1446.  
  1447.         STRUCTURE MusChannel,0
  1448.         APTR    ch_Instr
  1449.         APTR    ch_Map
  1450.         ULONG    ch_Pitch
  1451.         BYTE    ch_Vol
  1452.         BYTE    ch_Pan
  1453.  
  1454.  
  1455.         CNOP    0,4
  1456.  
  1457. Channels    dc.l    Channel0,Channel1,Channel2,Channel3
  1458.         dc.l    Channel4,Channel5,Channel6,Channel7
  1459.         dc.l    Channel8,Channel9,Channel10,Channel11
  1460.         dc.l    Channel12,Channel13,Channel14,Channel15
  1461.  
  1462.  
  1463.         CNOP    0,4
  1464.  
  1465. Channel0    dc.l    0        ; instrument
  1466.         dc.l    Channel0Map    ; note to voice map
  1467.         dc.l    0        ; pitch wheel setting
  1468.         dc.b    0        ; volume
  1469.         dc.b    0        ; pan setting
  1470.  
  1471.         CNOP    0,4
  1472.  
  1473. Channel1    dc.l    0        ; instrument
  1474.         dc.l    Channel1Map    ; note to voice map
  1475.         dc.l    0        ; pitch wheel setting
  1476.         dc.b    0        ; volume
  1477.         dc.b    0        ; pan setting
  1478.  
  1479.         CNOP    0,4
  1480.  
  1481. Channel2    dc.l    0        ; instrument
  1482.         dc.l    Channel2Map    ; note to voice map
  1483.         dc.l    0        ; pitch wheel setting
  1484.         dc.b    0        ; volume
  1485.         dc.b    0        ; pan setting
  1486.  
  1487.         CNOP    0,4
  1488.  
  1489. Channel3    dc.l    0        ; instrument
  1490.         dc.l    Channel3Map    ; note to voice map
  1491.         dc.l    0        ; pitch wheel setting
  1492.         dc.b    0        ; volume
  1493.         dc.b    0        ; pan setting
  1494.  
  1495.         CNOP    0,4
  1496.  
  1497. Channel4    dc.l    0        ; instrument
  1498.         dc.l    Channel4Map    ; note to voice map
  1499.         dc.l    0        ; pitch wheel setting
  1500.         dc.b    0        ; volume
  1501.         dc.b    0        ; pan setting
  1502.  
  1503.         CNOP    0,4
  1504.  
  1505. Channel5    dc.l    0        ; instrument
  1506.         dc.l    Channel5Map    ; note to voice map
  1507.         dc.l    0        ; pitch wheel setting
  1508.         dc.b    0        ; volume
  1509.         dc.b    0        ; pan setting
  1510.  
  1511.         CNOP    0,4
  1512.  
  1513. Channel6    dc.l    0        ; instrument
  1514.         dc.l    Channel6Map    ; note to voice map
  1515.         dc.l    0        ; pitch wheel setting
  1516.         dc.b    0        ; volume
  1517.         dc.b    0        ; pan setting
  1518.  
  1519.         CNOP    0,4
  1520.  
  1521. Channel7    dc.l    0        ; instrument
  1522.         dc.l    Channel7Map    ; note to voice map
  1523.         dc.l    0        ; pitch wheel setting
  1524.         dc.b    0        ; volume
  1525.         dc.b    0        ; pan setting
  1526.  
  1527.         CNOP    0,4
  1528.  
  1529. Channel8    dc.l    0        ; instrument
  1530.         dc.l    Channel8Map    ; note to voice map
  1531.         dc.l    0        ; pitch wheel setting
  1532.         dc.b    0        ; volume
  1533.         dc.b    0        ; pan setting
  1534.  
  1535.         CNOP    0,4
  1536.  
  1537. Channel9    dc.l    0        ; instrument
  1538.         dc.l    Channel9Map    ; note to voice map
  1539.         dc.l    0        ; pitch wheel setting
  1540.         dc.b    0        ; volume
  1541.         dc.b    0        ; pan setting
  1542.  
  1543.         CNOP    0,4
  1544.  
  1545. Channel10    dc.l    0        ; instrument
  1546.         dc.l    Channel10Map    ; note to voice map
  1547.         dc.l    0        ; pitch wheel setting
  1548.         dc.b    0        ; volume
  1549.         dc.b    0        ; pan setting
  1550.  
  1551.         CNOP    0,4
  1552.  
  1553. Channel11    dc.l    0        ; instrument
  1554.         dc.l    Channel11Map    ; note to voice map
  1555.         dc.l    0        ; pitch wheel setting
  1556.         dc.b    0        ; volume
  1557.         dc.b    0        ; pan setting
  1558.  
  1559.         CNOP    0,4
  1560.  
  1561. Channel12    dc.l    0        ; instrument
  1562.         dc.l    Channel12Map    ; note to voice map
  1563.         dc.l    0        ; pitch wheel setting
  1564.         dc.b    0        ; volume
  1565.         dc.b    0        ; pan setting
  1566.  
  1567.         CNOP    0,4
  1568.  
  1569. Channel13    dc.l    0        ; instrument
  1570.         dc.l    Channel13Map    ; note to voice map
  1571.         dc.l    0        ; pitch wheel setting
  1572.         dc.b    0        ; volume
  1573.         dc.b    0        ; pan setting
  1574.  
  1575.         CNOP    0,4
  1576.  
  1577. Channel14    dc.l    0        ; instrument
  1578.         dc.l    Channel14Map    ; note to voice map
  1579.         dc.l    0        ; pitch wheel setting
  1580.         dc.b    0        ; volume
  1581.         dc.b    0        ; pan setting
  1582.  
  1583.         CNOP    0,4
  1584.  
  1585. Channel15    dc.l    0        ; instrument
  1586.         dc.l    Channel15Map    ; note to voice map
  1587.         dc.l    0        ; pitch wheel setting
  1588.         dc.b    0        ; volume
  1589.         dc.b    0        ; pan setting
  1590.  
  1591.  
  1592.         CNOP    0,4
  1593.  
  1594. Channel0Map    dcb.b    128,0
  1595. Channel1Map    dcb.b    128,0
  1596. Channel2Map    dcb.b    128,0
  1597. Channel3Map    dcb.b    128,0
  1598. Channel4Map    dcb.b    128,0
  1599. Channel5Map    dcb.b    128,0
  1600. Channel6Map    dcb.b    128,0
  1601. Channel7Map    dcb.b    128,0
  1602. Channel8Map    dcb.b    128,0
  1603. Channel9Map    dcb.b    128,0
  1604. Channel10Map    dcb.b    128,0
  1605. Channel11Map    dcb.b    128,0
  1606. Channel12Map    dcb.b    128,0
  1607. Channel13Map    dcb.b    128,0
  1608. Channel14Map    dcb.b    128,0
  1609. Channel15Map    dcb.b    128,0
  1610.  
  1611. ;--------------------------------------
  1612.  
  1613.         STRUCTURE AudioVoice,0
  1614.         APTR    vc_Next
  1615.         APTR    vc_Channel
  1616.         APTR    vc_Wave
  1617.         ULONG    vc_Index
  1618.         ULONG    vc_Step
  1619.         ULONG    vc_Loop
  1620.         ULONG    vc_Length
  1621.         BYTE    vc_Vol
  1622.         BYTE    vc_Flags    ; b7 = SFX, b1 = RLS, b0 = EN
  1623.  
  1624.         CNOP    0,4
  1625.  
  1626. Voices        dc.l    Voice0,Voice1,Voice2,Voice3
  1627.         dc.l    Voice4,Voice5,Voice6,Voice7
  1628.         dc.l    Voice8,Voice9,Voice10,Voice11
  1629.         dc.l    Voice12,Voice13,Voice14,Voice15
  1630.  
  1631.         CNOP    0,4
  1632.  
  1633. Voice0        dc.l    Voice1
  1634.         dc.l    0        ; channel back-link
  1635.         dc.l    0        ; instrument wave data
  1636.         dc.l    0        ; sample index
  1637.         dc.l    0        ; sample rate
  1638.         dc.l    0        ; instrument loop point
  1639.         dc.l    0        ; instrument data length
  1640.         dc.b    0        ; voice volume scale
  1641.         dc.b    0        ; voice flags
  1642.  
  1643.         CNOP    0,4
  1644.  
  1645. Voice1        dc.l    Voice2
  1646.         dc.l    0        ; channel back-link
  1647.         dc.l    0        ; instrument wave data
  1648.         dc.l    0        ; sample index
  1649.         dc.l    0        ; sample rate
  1650.         dc.l    0        ; instrument loop point
  1651.         dc.l    0        ; instrument data length
  1652.         dc.b    0        ; voice volume scale
  1653.         dc.b    0        ; voice flags
  1654.  
  1655.         CNOP    0,4
  1656.  
  1657. Voice2        dc.l    Voice3
  1658.         dc.l    0        ; channel back-link
  1659.         dc.l    0        ; instrument wave data
  1660.         dc.l    0        ; sample index
  1661.         dc.l    0        ; sample rate
  1662.         dc.l    0        ; instrument loop point
  1663.         dc.l    0        ; instrument data length
  1664.         dc.b    0        ; voice volume scale
  1665.         dc.b    0        ; voice flags
  1666.  
  1667.         CNOP    0,4
  1668.  
  1669. Voice3        dc.l    Voice4
  1670.         dc.l    0        ; channel back-link
  1671.         dc.l    0        ; instrument wave data
  1672.         dc.l    0        ; sample index
  1673.         dc.l    0        ; sample rate
  1674.         dc.l    0        ; instrument loop point
  1675.         dc.l    0        ; instrument data length
  1676.         dc.b    0        ; voice volume scale
  1677.         dc.b    0        ; voice flags
  1678.  
  1679.         CNOP    0,4
  1680.  
  1681. Voice4        dc.l    Voice5
  1682.         dc.l    0        ; channel back-link
  1683.         dc.l    0        ; instrument wave data
  1684.         dc.l    0        ; sample index
  1685.         dc.l    0        ; sample rate
  1686.         dc.l    0        ; instrument loop point
  1687.         dc.l    0        ; instrument data length
  1688.         dc.b    0        ; voice volume scale
  1689.         dc.b    0        ; voice flags
  1690.  
  1691.         CNOP    0,4
  1692.  
  1693. Voice5        dc.l    Voice6
  1694.         dc.l    0        ; channel back-link
  1695.         dc.l    0        ; instrument wave data
  1696.         dc.l    0        ; sample index
  1697.         dc.l    0        ; sample rate
  1698.         dc.l    0        ; instrument loop point
  1699.         dc.l    0        ; instrument data length
  1700.         dc.b    0        ; voice volume scale
  1701.         dc.b    0        ; voice flags
  1702.  
  1703.         CNOP    0,4
  1704.  
  1705. Voice6        dc.l    Voice7
  1706.         dc.l    0        ; channel back-link
  1707.         dc.l    0        ; instrument wave data
  1708.         dc.l    0        ; sample index
  1709.         dc.l    0        ; sample rate
  1710.         dc.l    0        ; instrument loop point
  1711.         dc.l    0        ; instrument data length
  1712.         dc.b    0        ; voice volume scale
  1713.         dc.b    0        ; voice flags
  1714.  
  1715.         CNOP    0,4
  1716.  
  1717. Voice7        dc.l    Voice8
  1718.         dc.l    0        ; channel back-link
  1719.         dc.l    0        ; instrument wave data
  1720.         dc.l    0        ; sample index
  1721.         dc.l    0        ; sample rate
  1722.         dc.l    0        ; instrument loop point
  1723.         dc.l    0        ; instrument data length
  1724.         dc.b    0        ; voice volume scale
  1725.         dc.b    0        ; voice flags
  1726.  
  1727.         CNOP    0,4
  1728.  
  1729. Voice8        dc.l    Voice9
  1730.         dc.l    0        ; channel back-link
  1731.         dc.l    0        ; instrument wave data
  1732.         dc.l    0        ; sample index
  1733.         dc.l    0        ; sample rate
  1734.         dc.l    0        ; instrument loop point
  1735.         dc.l    0        ; instrument data length
  1736.         dc.b    0        ; voice volume scale
  1737.         dc.b    0        ; voice flags
  1738.  
  1739.         CNOP    0,4
  1740.  
  1741. Voice9        dc.l    Voice10
  1742.         dc.l    0        ; channel back-link
  1743.         dc.l    0        ; instrument wave data
  1744.         dc.l    0        ; sample index
  1745.         dc.l    0        ; sample rate
  1746.         dc.l    0        ; instrument loop point
  1747.         dc.l    0        ; instrument data length
  1748.         dc.b    0        ; voice volume scale
  1749.         dc.b    0        ; voice flags
  1750.  
  1751.         CNOP    0,4
  1752.  
  1753. Voice10        dc.l    Voice11
  1754.         dc.l    0        ; channel back-link
  1755.         dc.l    0        ; instrument wave data
  1756.         dc.l    0        ; sample index
  1757.         dc.l    0        ; sample rate
  1758.         dc.l    0        ; instrument loop point
  1759.         dc.l    0        ; instrument data length
  1760.         dc.b    0        ; voice volume scale
  1761.         dc.b    0        ; voice flags
  1762.  
  1763.         CNOP    0,4
  1764.  
  1765. Voice11        dc.l    Voice12
  1766.         dc.l    0        ; channel back-link
  1767.         dc.l    0        ; instrument wave data
  1768.         dc.l    0        ; sample index
  1769.         dc.l    0        ; sample rate
  1770.         dc.l    0        ; instrument loop point
  1771.         dc.l    0        ; instrument data length
  1772.         dc.b    0        ; voice volume scale
  1773.         dc.b    0        ; voice flags
  1774.  
  1775.         CNOP    0,4
  1776.  
  1777. Voice12        dc.l    Voice13
  1778.         dc.l    0        ; channel back-link
  1779.         dc.l    0        ; instrument wave data
  1780.         dc.l    0        ; sample index
  1781.         dc.l    0        ; sample rate
  1782.         dc.l    0        ; instrument loop point
  1783.         dc.l    0        ; instrument data length
  1784.         dc.b    0        ; voice volume scale
  1785.         dc.b    0        ; voice flags
  1786.  
  1787.         CNOP    0,4
  1788.  
  1789. Voice13        dc.l    Voice14
  1790.         dc.l    0        ; channel back-link
  1791.         dc.l    0        ; instrument wave data
  1792.         dc.l    0        ; sample index
  1793.         dc.l    0        ; sample rate
  1794.         dc.l    0        ; instrument loop point
  1795.         dc.l    0        ; instrument data length
  1796.         dc.b    0        ; voice volume scale
  1797.         dc.b    0        ; voice flags
  1798.  
  1799.         CNOP    0,4
  1800.  
  1801. Voice14        dc.l    Voice15
  1802.         dc.l    0        ; channel back-link
  1803.         dc.l    0        ; instrument wave data
  1804.         dc.l    0        ; sample index
  1805.         dc.l    0        ; sample rate
  1806.         dc.l    0        ; instrument loop point
  1807.         dc.l    0        ; instrument data length
  1808.         dc.b    0        ; voice volume scale
  1809.         dc.b    0        ; voice flags
  1810.  
  1811.         CNOP    0,4
  1812.  
  1813. Voice15        dc.l    0
  1814.         dc.l    0        ; channel back-link
  1815.         dc.l    0        ; instrument wave data
  1816.         dc.l    0        ; sample index
  1817.         dc.l    0        ; sample rate
  1818.         dc.l    0        ; instrument loop point
  1819.         dc.l    0        ; instrument data length
  1820.         dc.b    0        ; voice volume scale
  1821.         dc.b    0        ; voice flags
  1822.  
  1823. ;--------------------------------------
  1824.  
  1825.         STRUCTURE InstrumentRec,0
  1826.         APTR    in_Wave
  1827.         ULONG    in_Loop
  1828.         ULONG    in_Length
  1829.         BYTE    in_Flags
  1830.         BYTE    in_Base
  1831.  
  1832.  
  1833.         CNOP    0,4
  1834.  
  1835. Instruments    dcb.l    256,0
  1836.  
  1837.         CNOP    0,4
  1838.  
  1839. QuietInst    dc.l    0
  1840.         dc.l    0
  1841.         dc.l    0
  1842.         dc.b    0
  1843.         dc.b    0
  1844.  
  1845.  
  1846.         CNOP    0,4
  1847.  
  1848. InstrHandle    dc.l    0
  1849. InstrFile    dc.l    InstrName
  1850. InstrPool    dc.l    0
  1851.  
  1852. InstrName    dc.b    'PROGDIR:MIDI_Instruments',0
  1853.  
  1854.         CNOP    0,4
  1855.  
  1856. validInstr    dc.b    %11111111    ; (00-07) Piano
  1857.         dc.b    %11111111    ; (08-0F) Chrom Perc
  1858.         dc.b    %11111111    ; (10-17) Organ
  1859.         dc.b    %11111111    ; (18-1F) Guitar
  1860.         dc.b    %11111111    ; (20-27) Bass
  1861.         dc.b    %11111111    ; (28-2F) Strings
  1862.         dc.b    %11111111    ; (30-37) Ensemble
  1863.         dc.b    %11111111    ; (38-3F) Brass
  1864.         dc.b    %11111111    ; (40-47) Reed
  1865.         dc.b    %11111111    ; (48-4F) Pipe
  1866.         dc.b    %11111111    ; (50-57) Synth Lead
  1867.         dc.b    %11111111    ; (58-5F) Synth Pad
  1868.         dc.b    %11111111    ; (60-67) Synth Effects
  1869.         dc.b    %11111111    ; (68-6F) Ethnic
  1870.         dc.b    %11111111    ; (70-77) Percussive
  1871.         dc.b    %11111111    ; (78-7F) SFX
  1872.         dc.b    %00000001    ; (80-87) invalid,Drum
  1873.         dc.b    %11111111    ; (88-8F) Drums/Clap/Hi-Hat
  1874.         dc.b    %11111111    ; (90-97) Hi-Hats/Toms/Cymb1
  1875.         dc.b    %11111111    ; (98-9F) Cymbals/Bells/Slap
  1876.         dc.b    %11111111    ; (A0-A7) Bongos/Congas/Timb
  1877.         dc.b    %11111111    ; (A8-AF) Agogo/Whistles/Gui
  1878.         dc.b    %11111100    ; (B0-B7) Claves/Block/Trian
  1879.         dc.b    %00000000    ; (B8-BF) invalid
  1880.         dc.b    %00000000    ; (C0-C7)
  1881.         dc.b    %00000000    ; (C8-CF)
  1882.         dc.b    %00000000    ; (D0-D7)
  1883.         dc.b    %00000000    ; (D8-DF)
  1884.         dc.b    %00000000    ; (E0-E7)
  1885.         dc.b    %00000000    ; (E8-EF)
  1886.         dc.b    %00000000    ; (F0-F7)
  1887.         dc.b    %00000000    ; (F8-FF)
  1888.  
  1889. ;--------------------------------------------------------------------
  1890.         section    PlayMusChip,data_c
  1891.  
  1892. ClearBuf    dcb.b    160,0
  1893.  
  1894.  
  1895. chipbuffer2    dcb.b    320,0
  1896. chipbuffer3    dcb.b    320,0
  1897.  
  1898. ;------------------------------------------------------------------------
  1899.         section    PlayMusBSS,bss
  1900.  
  1901. EventBlocks    ds.w    32768
  1902.  
  1903.  
  1904. tempAudio    ds.b    160
  1905.  
  1906. ;------------------------------------------------------------------------
  1907.  
  1908.         end
  1909.